package com.example.rest.controller;

import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.List;

/**
 * @BelongsProject: RestTemplate
 * @BelongsPackage: com.example.rest.controller
 * @Author:hlzs1
 * @Description: 描述什么人干什么事儿
 * @CreateTime: 2023-02-28 09:00
 * @Version: 1.0
 */
@RestController
public class HttpController {

    /**
     * @description:get请求，带一个name作为参数
     * @author: haolizhuo
     * @date: 2023/2/28
     * @param: [name]
     * @return: java.lang.String
     **/
    @GetMapping("/hello")
    public String sayHello(String name) {
        return "hello " + name + " !";
    }


    /**
     * @description:post请求，带一个name作为参数
     * @author: haolizhuo
     * @date: 2023/2/28
     * @param: [name]
     * @return: java.lang.String
     **/
    @PostMapping("/hello2")
    public String postSayHello(@RequestBody String name){
        return "hello " + name + " !";
    }


    /**
     * @description:post请求，带一个name作为参数
     * @author: haolizhuo
     * @date: 2023/2/28
     * @param: [name]
     * @return: java.lang.String
     **/
    @PutMapping("/hello3")
    public void  putSayHello(@RequestBody String name){
        System.out.println("put请求被调用了，hello"+name);
    }

    /**
     * @description:delete请求，地址传参
     * @author: haolizhuo
     * @date: 2023/2/28
     * @param: [name]
     * @return: java.lang.String
     **/
    @DeleteMapping("/hello4/{name}")
    @ResponseBody
    public void  deleteSayHello( @PathVariable String name){
        System.out.println("delete请求被调用了，hello"+name);
    }


    @GetMapping("/customheader")
    public String customHeader(HttpServletRequest req) {
        return req.getHeader("cookie");
    }

    @GetMapping("/testhlz")
    public void testHlz(){
        List<String> list = new ArrayList<>();
        int i = 0;
        while(true){
            list.add("333");
            System.out.println(i++);
        }
    }

}
